<?php
defined('BY_JYA') or exit('error');
global $_RQ,$_AR;
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
$return=array();
if($_RQ['op']=='list'){
	$params=array('uniacid'=>$_SESSION['uniacid'],'type'=>intval($_RQ['type']));
	if($_RQ['title']){
		$params2=array('uniacid'=>$_SESSION['uniacid']);
		$params2['title like']='%'.trim($_RQ['title']).'%';
		$return['params']['title']=$_RQ['title'];
		$shifuid=pdo_getall('jy_wxshifu_member',$params2,array('title','id'),'id');
		if($shifuid){
			$shifuid=array_keys($shifuid);
		}else{
			$shifuid=-1;
		}
		$params['shifuid']=$shifuid;
	}
	$orderby=array();
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$total='';
	$list=pdo_getslice('jy_wxshifu_jiang_log',$params,array($pindex,$psize),$total,$fields,'','id desc');
	foreach($list as &$item){
			$item['member']=cfc('core')->member_show($item['mid']);
	}
	$return['list']=$list?$list:array();
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',
		'tabs'=>array(
			array('op'=>'list','title'=>'奖罚列表'),
		),
		'list'=>array('data'=>'list','edit'=>false,'list'=>array(
			array('name'=>'member','title'=>'师傅','type'=>'member'),
			array('name'=>'type','title'=>'类型','type'=>'radio','options'=>'jianglog_type'),
			array('name'=>'money','title'=>'金额','type'=>'string'),
			array('name'=>'createtime','title'=>'创建时间','type'=>'string'),
			array('name'=>'status','title'=>'状态','type'=>'radio','options'=>'jianglog_status'),
		)),
		'search_one'=>array('name'=>'title','help'=>'师傅姓名','add'=>false),
	);
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='edit'){
	$item=$this->pdo_get('comments',array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
	$return['item']=$item;
	$return['htmls']=array(
			'type'=>'edit',
			'post'=>'post',
			'edit'=>array(
				array('name'=>'star','title'=>'评价星级','type'=>'star'),
				array('name'=>'content','title'=>'评价内容','type'=>'text'),
				array('name'=>'show','title'=>'是否显示','type'=>'switch'),
			),
	);	
	exi($return);
}
if($_RQ['op']=='post'){
	$postdata=get_postdata();
	$data=array(
		'show'=>trim($postdata['show']),
		'star'=>trim($postdata['star']),
		'content'=>trim($postdata['content'])
	);
	$id=intval($postdata['id']);
	if($id){
		pdo_update('jy_wxshifu_jiang_log',$data,array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
		exi('评价修改成功！');
	}else{
		exi('没有找到相关评价');
	}
}
if($_RQ['op']=='del'){
	$id=intval($_RQ['id']);
	if($id){
		pdo_delete('jy_wxshifu_jiang_log',array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
	}
	$del=trim($_RQ['del'],';');
	if($del){
		$del=explode(';',$del);
		foreach($del as $id){
			$id=intval($id);
			if($id){
				pdo_delete('jy_wxshifu_jiang_log',array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
			}
		}
	}
	exi('删除成功！');
}